import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.0
import QtQuick.XmlListModel 2.0
import QtQuick.Controls.Styles 1.0



ApplicationWindow {
    id: mainWindow
    title: qsTr("DTwenty Campaign Tool")

    width: 1200
    height: 800

    XmlListModel {
        id: mainModel
        source: "file:///C:/Users/Jussi/SkyDrive/Games/DnD/Projects/DnD_MnM/Magic and Machine Guns 7.xml"
        query: "/Campaign" // query root element, so we won't get error from qmlscene.exe
    }

    XmlListModel {
        id: skillsModel

        source: mainModel.source
        query: "/Campaign/Skills/Skill"

        XmlRole { name: "name"; query: "attribute::name/string()" }
        XmlRole { name: "attribute"; query: "attribute::attribute/string()" }

        onStatusChanged: {
            if (status !== XmlListModel.Ready)
            {
                return;
            }

            middlePane.editIndex = 0;
            rightPane.editIndex = 0;

            middlePane.state = "Skills";
            rightPane.state = "Skills";
        }
    }

    XmlListModel {
        id: characterModel

        source: mainModel.source
        query: "/Campaign/CharacterClasses/CharacterClass"

        XmlRole { name: "name"; query: "attribute::name/string()" }
        XmlRole { name: "acronym"; query: "substring(attribute::name, 1, 3)" }
        XmlRole { name: "hitDieIndex"; query: "child::CharacterFeatures/child::HitDie/attribute::category/number()" }
        XmlRole { name: "skillPointIndex"; query: "child::CharacterFeatures/child::SkillPoints/attribute::category/number()" }
        XmlRole { name: "baseAttackIndex"; query: "child::CharacterFeatures/child::BaseAttackBonus/attribute::category/number()" }
        XmlRole { name: "skills"; query: "string-join(child::Skills/child::Skill/attribute::name, ';')" }
    }

    Action {
        id: createCharacter
        text: "Create Character"
        shortcut: "CTRL+R"
        onTriggered: {
            characterModel.append({
                                     "name": "New Character Class",
                                     "acronym": "-",
                                     "skills": "General Athletics;Streetwise",
                                     "hitDieIndex": 0,
                                     "skillPointIndex": 0,
                                     "baseAttackIndex": 0
                                 });
        }
    }

    Action {
        id: createSkill
        text: "Create Skill"
        shortcut: "CTRL+T"
        onTriggered: {
            skillsModel.append({
                                 "name": "New Skill",
                                 "attribute": 0,
                                 "collection": false
                             })
        }
    }

    color: "black"
    ListModel {
        id: attributeList
        ListElement {
            name: "Strength"
        }
        ListElement {
            name: "Dexterity"
        }
        ListElement {
            name: "Constitution"
        }
        ListElement {
            name: "Intelligence"
        }
        ListElement {
            name: "Wisdom"
        }
        ListElement {
            name: "Charisma"
        }
    }

    ListModel {
        id: hitDiceList
        ListElement { value: 4; name: "D4" }
        ListElement { value: 6; name: "D6" }
        ListElement { value: 8; name: "D8" }
        ListElement { value: 10; name: "D10" }
        ListElement { value: 12; name: "D12" }
    }

    ListModel {
        id: skillPointsList
        ListElement { value: 2; name: "Uneducated" }
        ListElement { value: 4; name: "Skilled" }
        ListElement { value: 6; name: "Expert" }
        ListElement { value: 8; name: "Master" }
    }

    ListModel {
        id: bonusList
        ListElement { name: "Base Attack";      acronym: "BA"; categoryStart: 0; category: "attack" }
        ListElement { name: "Fortitude Save";   acronym: "Fort"; categoryStart: 1; category: "save" }
        ListElement { name: "Reflex Save";      acronym: "Ref"; categoryStart: 1; category: "save" }
        ListElement { name: "Willpower Save";   acronym: "Will"; categoryStart: 1; category: "save" }
    }

    ListModel {
        id: bonusCategoryList
        ListElement { name: "Poor";     value: 0 }
        ListElement { name: "Normal";   value: 1 }
        ListElement { name: "Good";     value: 2 }
    }

//    ListModel {
//        id: featureList
//        ListElement { name: "Hit Die" }
//        ListElement { name: "Skill Points" }
//        ListElement { name: "Bonuses" }
//    }


//    ListModel {
//        id: skillList
//        ListElement {
//            name: "Computer Use"
//            attribute: 3
//            collection: false
//            description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet dolor tincidunt tortor scelerisque posuere. Fusce eros sem, rutrum at lobortis non, viverra at ligula. Nullam pellentesque odio at ipsum luctus, ac tempor risus faucibus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus rhoncus facilisis leo non aliquet. Fusce iaculis et est ac ornare. Sed placerat magna sit amet purus viverra, quis interdum turpis hendrerit. Vivamus tincidunt fringilla lectus, in semper metus. Integer vitae dolor odio. Integer ullamcorper pellentesque vestibulum. Curabitur turpis leo, molestie ut fringilla id, dapibus sed odio. Lorem ipsum dolor sit amet, consectetur adipiscing elit."
//        }
//        ListElement {
//            name: "Craft"
//            attribute: 3
//            collection: true
//            description: "Quisque non justo nec sem tristique ornare. Maecenas a facilisis massa. Phasellus sodales hendrerit accumsan. Pellentesque nec pharetra justo. Donec in dolor ipsum. Cras sagittis vestibulum odio ac fermentum. Integer vulputate ut lacus a tempor. Curabitur laoreet justo sit amet felis sodales facilisis."
//        }
//        ListElement {
//            name: "General Athletics"
//            attribute: 0
//            collection: false
//            description: "In accumsan elementum hendrerit. Mauris ornare tortor ullamcorper, euismod leo et, scelerisque sem. Proin eu bibendum tellus. Aliquam et nulla metus. Donec egestas tortor semper mollis scelerisque. Quisque et lorem ante. Donec pretium justo ac sapien posuere faucibus. Suspendisse at lorem in magna scelerisque blandit. Nulla at sapien in nibh rutrum consectetur. Sed justo mi, tincidunt eget massa et, ultrices tempor enim. Vivamus interdum luctus faucibus. Pellentesque consectetur, ipsum id consequat tincidunt, dui lorem consectetur tellus, id posuere ipsum arcu eu velit. Fusce sit amet purus in tellus facilisis mattis. Morbi ultrices velit lorem, quis convallis dui laoreet nec. Vestibulum porta lacinia nibh, vitae semper eros auctor a. Cras ut risus odio."
//        }
//        ListElement {
//            name: "Knowledge"
//            attribute: 3
//            collection: true
//            descrition: "Sed pharetra massa a luctus fringilla. Nunc sit amet erat eu metus pellentesque auctor. Donec ullamcorper ultricies faucibus. Sed ullamcorper odio et molestie elementum. Nunc ac venenatis lacus, vitae fringilla eros. Mauris rhoncus quam ac purus porttitor, convallis suscipit dui egestas. Nunc cursus neque sem, at rutrum lacus pulvinar in. Cras ultrices tellus enim, quis adipiscing sem fringilla in. Aenean egestas quam ac fringilla tempor. Suspendisse consectetur odio ullamcorper lorem suscipit, dignissim rhoncus dui convallis. Sed massa enim, mollis sed justo vel, posuere fermentum eros. Morbi condimentum pretium commodo."
//        }
//        ListElement {
//            name: "Streetwise"
//            attribute: 5
//            collection: false
//            description: "Maecenas id faucibus quam. In condimentum, purus et pretium dignissim, dui arcu interdum erat, vitae aliquam odio mauris sit amet magna. Praesent in nulla eu leo elementum vehicula placerat eget quam. Duis mattis eleifend tortor, non vehicula nulla vestibulum ac. Sed tellus purus, egestas ac ipsum a, egestas ullamcorper felis. Morbi bibendum eleifend dignissim. Cras consectetur metus eu est vulputate, ut luctus lorem auctor. Aliquam leo est, tincidunt quis posuere sed, molestie et nunc. Nullam eu ornare felis, in luctus justo. Nullam pretium tincidunt erat eu volutpat. Donec mattis id elit in porttitor. Donec sagittis dictum est, et ultrices nisl pulvinar eget. Nullam interdum non lacus sed dapibus. Donec tempus nulla nec malesuada scelerisque."
//        }
//    }

//    ListModel {
//        id: subskillList

//        ListElement {
//            name: "Programming"
//            skill: "Craft"
//        }

//        ListElement {
//            name: "History"
//            skill: "Knowledge"
//        }
//    }

    ListModel {
        id: specialsList
        ListElement { name: "Backstab" }
        ListElement { name: "Track" }
        ListElement { name: "Arcane Spells" }
        ListElement { name: "Divine Spells" }
    }


//    ListModel {
//        id: characterList

//        ListElement {
//            name: "Die Hard"
//            acronym: "DHa"
//            skills: "General Athletics;Streetwise"
//            hitDieIndex: 4
//            skillPointIndex: 0
//            baseAttackIndex: 2
//        }
//        ListElement {
//            name: "Grease Monkey"
//            acronym: "GMo"
//            skills: "Craft;Streetwise"
//            hitDieIndex: 3
//            skillPointIndex: 2
//            baseAttackIndex: 1
//        }
//        ListElement {
//            name: "Urbanomancer"
//            acronym: "Urb"
//            skills: "Computer Use;Knowledge"
//            hitDieIndex: 0
//            skillPointIndex: 1
//            baseAttackIndex: 0
//        }
//    }

    ListModel {
        id: dtwentyList
//        ListElement { name: "Features"; index: 0 }
//        ListElement { name: "Specials"; index: 1 }
        ListElement { name: "Skills" }
        //        ListElement { name: "Feats";    index: -1 }
        //        ListElement { name: "Arcane Spells";    index: -1 }
        //        ListElement { name: "Divine Spells";    index: -1 }
    }




    VerticalSplitter  {
        id: leftSplitter
        x: 200
    }

    VerticalSplitter {
        id: rightSplitter
        x: parent.width - 200
    }

    Rectangle {
        id: leftPane
        color: "lightsteelblue"

        anchors.left: parent.left
        anchors.right: leftSplitter.left
        anchors.top: parent.top
        anchors.bottom: parent.bottom


        PanelMenu {
            id: coreMenu
            title: "DTwenty Core"
            model: dtwentyList
            hoverColor: "steelblue"

            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right

            onClickedText: {
                middlePane.state = "";
                rightPane.state = "";
                middlePane.editIndex = 0;
                rightPane.editIndex = 0;
                middlePane.state = text;
                rightPane.state = text;
            }

        }

        PanelMenu {
            id: charactersMenu
            title: "DTwenty Characters"
            model: characterModel
            hoverColor: "steelblue"

            anchors.top: coreMenu.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom

            anchors.topMargin: 12

            onClickedIndex: {
                middlePane.state = "";
                rightPane.state = "";
                middlePane.editIndex = index;
                rightPane.editIndex = index;
                middlePane.state = "Character";
                rightPane.state = "Character";
            }
        }
    }

    MiddlePane {
        id: middlePane

        anchors.top: parent.top
        anchors.right: rightSplitter.left
        anchors.bottom: parent.bottom
        anchors.left: leftSplitter.right

        anchors.leftMargin: 1
    }

    RightPane {
        id: rightPane

        anchors.left: rightSplitter.right
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.bottom: parent.bottom
    }


        /*
            - view campaign features (hd, skill points, bonuses)
            - edit skill name, description, attribute, subskills setting
            - edit special name, description, multiuse setting, (character classes + levels)
            - edit feat name, description(, requirements)
            - edit character class features (name, hd, skill points, bonus categories)
            - edit character class skills
            - edit character class levels (create/add/remove special)
        */

}
